using System;
using System.Collections.Generic;
using System.Text;

namespace Emlyn.Common.Data.SqlServer.SqlDBAccess
{
    // This subclass of TSimpleSQLProblemHandler hands off handling of exceptions to a delegate.
    // With no delegate set, it simply ignores exceptions (causing them to 
    // be raised by the TSimpleSQL calls).
    public class SimpleSQLGenericProblemHandler : SimpleSQLProblemHandler
    {
        private SimpleSQLExceptionHandlerDelegate fSimpleSQLExceptionHandlerDelegate = null;
        private SimpleSQLSuccessHandlerDelegate fSimpleSQLSuccessHandlerDelegate = null;

        public override void SimpleSQLException(Exception aException, int aTryNumber, ref bool aRetry)
        {
            if (SimpleSQLExceptionHandlerDelegate != null)
                SimpleSQLExceptionHandlerDelegate(aException, aTryNumber, ref aRetry);
            else
                aRetry = false;
        }

        public override void SimpleSQLSuccess(int aTryNumber)
        {
            if (SimpleSQLSuccessHandlerDelegate != null)
                SimpleSQLSuccessHandlerDelegate(aTryNumber);
        }

        public SimpleSQLExceptionHandlerDelegate SimpleSQLExceptionHandlerDelegate
        {
            get
            {
                return fSimpleSQLExceptionHandlerDelegate;
            }
            set
            {
                fSimpleSQLExceptionHandlerDelegate = value;
            }
        }

        public SimpleSQLSuccessHandlerDelegate SimpleSQLSuccessHandlerDelegate
        {
            get
            {
                return fSimpleSQLSuccessHandlerDelegate;
            }
            set
            {
                fSimpleSQLSuccessHandlerDelegate = value;
            }
        }
    }
}
